<?php

// Namespace

namespace Loop;


/**
 * IDatabaseDriver is an interface that defines various operations related to databases (e.g. connect, execute a query...)
 * It must be implemented by a class for each database platform (e.g. CMySqlIDriver for the myslqi driver)
 *
 * @package		Loop
 * @category	Driver
 */

interface IDatabaseDriver
{
	/**
	 *
	 */
	
	public function __construct($extensionId);


	/**
	 * Connects to the database specified in the preferences
	 */
	
	public function connect($host = null, $login = null, $password = null, $name = null, $port = null, $socket = null);
	

	/**
	 * Close transaction
	 */
	
	public function closeTransaction();	


	/**
	 * Disconnects from the database
	 */
	
	public function disconnect();
	
	
	/**
	 * Dumps the database data into SQL queries
	 *
	 * @param	string	$pathToFile	The path to the file whi will receive the dump
	 *
	 * @return	string				SQL queries
	 */
	
	public function dumpData($pathToFile);
	
	
	/**
	 * Executes a SQL query
	 *
	 * @param	string	$query			The SQL query (without any external data)
	 * @param	array	$queryVariables	Variables to be injected in the query
	 * @param	string	$finalQuery		The final SQL query
	 *
	 * @return	mixed					The result of the query
	 */
	
	public function executeQuery($query, $queryVariables = null, &$finalQuery = null);
	
	
	/**
	 * Executes multiple SQL queries
	 *
	 * @param	string	$queries	The SQL queries
	 * @param	bool	$isSecure	True to stop when a query fails, false to ignore failures
	 *
	 * @return	array				An array of results
	 */
	
	public function executeQueries($queries, $isSecure = true);
	
	
	/**
	 * Fetches the first result of a query into an associative array
	 *
	 * @param	string	$result	The result
	 *
	 * @return	array			An associative array
	 */
	
	public function fetchAssociativeArray(&$result);
	
	
	/**
	 * Fetches the first result of a query into an indexed array
	 *
	 * @param	string	$result	The result
	 *
	 * @return	array			An indexed array
	 */
	
	public function fetchRow(&$result);

	
	/**
	 * Gets the latest ID inserted into the database
	 *
	 * @return	int	The last ID inserted into the database
	 */
	
	public function getLastId();
	
	
	/**
	 * Gets the number of fields of a SQL result
	 *
	 * @param	string	$result	The result
	 *
	 * @return	int				The number of fields
	 */
	
	public function getNbFields(&$result);
	
	
	/**
	 * Gets the number of affected rows of a SQL result
	 *
	 * @return	int	The number of affected rows
	 */
	
	public function getNbAffectedRows();
	
	
	/**
	 * Gets the number of rows of a SQL result
	 *
	 * @param	string	$result	The result
	 *
	 * @return	int				The number of rows
	 */
	
	public function getNbRows(&$result);
	
	
	/**
	 * Checks whether the driver is connected to a database
	 *
	 * @return	bool	True if connected, false otherwise
	 */
	
	public function isConnected();
	

	/**
	 * Check if a table exist in database
	 *
	 * @return	boolean true or false
	 */
	
	public function isTableCreated($databaseName, $tableName);

	
	/**
	 * Gets the list of tables contained in the database
	 *
	 * @return	array	The names of tables
	 */
	
	public function listTables();
	
	
	/**
	 * Gets the list of tables and views contained in the database
	 *
	 * @return	array	The names of tables and views
	 */
	
	public function listTablesAndViews();
	
	
	/**
	 * Secures a string before injection
	 *
	 * @param	string $string The string to be secured
	 *
	 * @return	string A safe(r) string, ready to be injected
	 */
	
	public function secureString($string);


	/**
	 * Start transaction
	 */
	
	public function startTransaction();	
}

?>
